from selenium.webdriver import ActionChains
from selenium.webdriver import Keys
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions

def demo1():
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get("http://localhost/ranzhi/www")
    WebDriverWait(driver,10).until(expected_conditions.presence_of_element_located((By.ID, 'account')))
    driver.find_element(By.ID, 'account').send_keys('admin')
    
    WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.ID, 'password')))
    driver.find_element(By.ID, 'password').send_keys('123456')
    
    WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.ID, 'submit')))
    driver.find_element(By.ID, 'submit').click()
    
    WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.CSS_SELECTOR, '#s-menu-superadmin > button')))
    driver.find_element(By.CSS_SELECTOR, '#s-menu-superadmin > button').click()
    
    WebDriverWait(driver, 10).until(expected_conditions.frame_to_be_available_and_switch_to_it('iframe-superadmin'))
    # driver.switch_to.frame('iframe-superadmin')
    driver.find_element(By.LINK_TEXT,'添加成员').click()
    print(driver.title)
    # driver.switch_to.parent_frame()
    # driver.find_element(By.CSS_SELECTOR, '#bottomRightBar > ul > li:nth-child(2) > a').click()
    # sleep(3)
    driver.close()
    driver.quit()


if __name__ == '__main__':
    demo1()